﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class DALBookingItem : IDALBookingItem, IDisposable
    {
        private CarBatteryEntities context;
        private bool disposed = false;

        public DALBookingItem(CarBatteryEntities context)
        {
            this.context = context;
        }

        public IEnumerable<BookingItem> GetBookingItemsFromBooking(int bookingID)
        {
            return context.BookingItem.Where(x => x.bookingID.Equals(bookingID)).AsEnumerable();
        }

        public BookingItem GetBookingItemByID(int bItemID)
        {
            return context.BookingItem.Find(bItemID);
        }

        public void AddBookingItem(BookingItem bItem)
        {
            context.BookingItem.Add(bItem);
        }

        public void DeleteBookingItem(int bItemID)
        {
            context.BookingItem.Remove(GetBookingItemByID(bItemID));
        }

        public int Save()
        {
            return context.SaveChanges();
        }

        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                    context.Dispose();
            }

            this.disposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
    }
}